/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package wifipositioner;

import java.util.Arrays;
import java.util.List;
import org.pi4.locutil.GeoPosition;

/**
 *
 * @author hh
 */
public class PositionCalculationResult {
    
    private GeoPosition estimated;
    private GeoPosition real;

    public PositionCalculationResult(GeoPosition estimated, GeoPosition real) {
        this.estimated = estimated;
        this.real = real;
    }
    
    public GeoPosition getEstimated() {
        return estimated; 
    }

    public GeoPosition getReal() {
        return real; 
    }
    
    @Override
    public String toString() {
        return estimated.getX() + ";" + estimated.getY() + ";" + real.getX() + ";" + real.getY();
    }
    
    public static PositionCalculationResult parse(String csvLine) throws Exception
    {
        List<String> tokens = Arrays.asList(csvLine.split(";"));
        
        if(tokens.size() == 4)
        {
            GeoPosition estimated = new GeoPosition(Double.parseDouble(tokens.get(0)), Double.parseDouble(tokens.get(1)));
            GeoPosition real = new GeoPosition(Double.parseDouble(tokens.get(2)), Double.parseDouble(tokens.get(3)));
            PositionCalculationResult result = new PositionCalculationResult(estimated, real);
        
            return result;
        }
        else
        {
            throw new Exception("Unrecognized csv line.");
        }
    }
}
